// re.hpp
// Some functions to construct regular expression NFA.
//
// Copyright (C) 2008  Maksim Sipos <msipos@mailc.net>
//
// This file is a part of the Ripe language project.
//
// Ripe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef R_RE_HPP
#define R_RE_HPP

#include "standard.hpp"
#include "util/nfa.hpp"

namespace Ripe {
  // Regular expression was not formed correctly.
  class ErrorInvalidRE : public Exception {};

  // Compile a regular expression into a NFA node graph. term_id is the id that
  // will be applied to the terminator state in the NFA.
  NFANode* re_compile(const char* expression, int term_id);

  // Match an NFA to a string.
  //  - greedy If this is set to true, will try to match as many chars as
  //    possible. Otherwise, shortest match will be returned.
  // Return true if match succeeded. *id is set to the id of the match that was
  // made. (This is only useful in the lexer.)
  bool re_match(const char* s, NFANode* pattern, bool greedy, int* id, 
                int* length);
}

#endif /* R_RE_HPP */
